import { Component, OnInit } from '@angular/core';
import {User} from "../../user/model/user-model";
import {flyIn} from '../../animations/fly-in';
import {Http, Headers, Response} from '@angular/http';
import {ActivatedRoute, Router, Params} from '@angular/router';
import {Post} from "../model/post-model";

@Component({
  selector: 'app-write-post1',
  templateUrl: './write-post1.component.html',
  styleUrls: ['./write-post1.component.scss'],
  animations: [
    flyIn
  ]
})
export class WritePost1Component implements OnInit {

  post: Post = new Post();

  constructor(public http: Http,public router:Router) { }

  ngOnInit() {
  }

  apply() {
    let user: User;
    user = JSON.parse(localStorage.getItem("currentUser"));
    this.post.author = user.userName;
    this.http.post('http://localhost:3000/posts', this.post)
      .subscribe(data => {
        console.log(data.json())
        this.router.navigateByUrl('');
      });
    console.log(this.post);

  }
}
